#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''=================================================
@Project -> File   ：GetCSProduct_New -> product
@IDE    ：PyCharm
@Author ：Json
@Date   ：2021-03-31 10:58
@Desc   ：
=================================================='''
import json

from cs_api.base import Client


class Products(Client):
    URI = "/product/"

    def __init__(self, rcustomerno):
        super().__init__(rcustomerno)

    def get_product_by_csid(self, csid, location='HK'):
        """
        location: HK or US
        :return:{"code":200,"msg":"请求成功","result":{"partNoList":{"Universal":["DF-UC020"],"Garmin":["361-00053-00","010-11599-00","010-11654-03","361-00053-04"]},"fitModelList":{"Universal":["DF-UC020"],"Garmin":["Montana 600","Montana 600T","Montana 650","Montana 650T","Monterra","Montana 600t Camo","Montana 680","Montana 680T"]},"productDetail":{"capacity":"2200mAh","category":"GPS, Navigator","color":"Black","dimension":"53.33 x 34.40 x 11.00mm","eanCode":"4894128085386","grossWeight":"70g / 2.47oz","issueDate":"03/06/2018","itemNo":"CS-GRM600XL","netWeight":"45.0g / 1.59oz","newPrice":"11.50","oldPrice":"13.50","otherInfo":"","productPriceDto":{"deCurrency":"EUR","deLocation":"Germany","dePrice":"11.5000","deStock":3,"hkCurrency":"USD","hkLocation":"Hong Kong","hkPrice":"10.0000","hkStock":79,"usCurrency":"USD","usLocation":"USA","usPrice":"12.0000","usStock":23},"rate":"8.14Wh","type":"Li-ion","volt":"3.7V"}}}
        """
        data = {
            'itemNo': csid,
            'lang': 'zh_cn',
            'region': location
        }
        return self.make_request("POST", "getProductById", data)

    def get_product_image(self, csid, location='HK'):
        data = {
            'itemNo': csid,
            'lang': 'zh_cn',
            'region': location  # US
        }
        return self.make_request('POST', 'queryAllImgByItemNo', data)

    def down_product(self, product_type, location,startDate = '',endDate = ''):
        """
        url ：https://api.cameronsino.com/b2d/api/home/product/export
        :param product_type: New product 新产品
        :param location: HK or US
        :return:
        """
        data = {
            'endDate': '',
            'lang': "zh_cn",
            'productType': product_type,
            'region': location,
            'startDate': '',
        }
        return self.make_request('POST', '/home/product/export', data)


if __name__ == '__main__':
    products = Products(2119)
    # products.test_request = True
    result = products.get_product_by_csid('CS-MPR074FT')
    print(result.json())

    # result = products.get_product_image('CS-GRM600XL')
    # print(result.json())
